<?php
/**
 * Quick hack to create a simple captcha image.
 */
session_start();
require_once('config.php');

define('PX_PER_FONT', 10);
define('FONT_HEIGHT', 20);
 
#$CONFIG['captcha_width'], 
    #$CONFIG['captcha_height'], $CONFIG['captcha_num_chars']);

$code = substr(md5(rand(0, 2000)), 0, $CONFIG['captcha_num_chars']);
$code = strtolower($code);
$_SESSION['captcha'] = $code;

$image = imagecreate(PX_PER_FONT * $CONFIG['captcha_num_chars'], FONT_HEIGHT);

// draw bg
$color = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $color);

// add text
$color = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 0, 0, $code, $color);

$resized = imagecreate($CONFIG['captcha_width'], $CONFIG['captcha_height']);
imagecopyresampled($resized, $image, 
    0, 0, 
    0, 0,
    $CONFIG['captcha_width'],
    $CONFIG['captcha_height'],
    PX_PER_FONT * $CONFIG['captcha_num_chars'],
    FONT_HEIGHT);
imagedestroy($image);

header('Content-Type: image/png');
imagepng($resized);
imagedestroy($resized);


?>
